﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExamStrategy.Question;

namespace ExamStrategy.Answer
{
    class Jimson : IExamStrategy
    {
        public int GetMaxScore(int[] values, int[] times)
        {
            int counter = 0;
            int Alltime = 0;
            Dictionary<int, int> arrs = new Dictionary<int, int>();
            try
            {

                if (values.Length == times.Length && times.Length > 0 && times.Length < 32)
                {
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (values[i] > 0 && times[i] > 0)
                        {
                            arrs.Add(values[i], times[i]);
                        }
                        else
                        {
                            return -1;
                        }
                    }

                    var result = from pair in arrs orderby pair.Key descending select pair;

                    foreach (KeyValuePair<int, int> item in result)
                    {
                        if (Alltime + item.Value <= 100)
                        {
                            counter += item.Key;
                            Alltime += item.Value;
                        }
                        else
                        {
                            continue;
                        }
                    }

                    return counter;
                }
                else
                {
                    return -1;
                }
            }
            catch (Exception)
            {

                return -1;
            }

        }
    }
}
